import config from '../../config/index.js'
Component({
    properties: {
        contents: {
            type: Array,
            value: [],
        }
    },
    data: {
    	mediaUrl:config.mediaUrl
    },
    attached() {},
    ready() {},
    moved() {},
    detached() {},
    methods: {
        // 点击，文件，图片
        clicMediaItem(e) {
            console.log(e)
            let item = e.currentTarget.dataset.value
            switch (item.type) {
                case 'document':
                    wx.showLoading({
                        title: '正在加载文档...',
                        mask: true
                    })
                    wx.downloadFile({
                        url: config.staticUrl + item.url,
                        success(res) {
                            wx.hideLoading()
                            var filePath = res.tempFilePath
                            wx.openDocument({
                                filePath: filePath,
                                fail() {}
                            })
                        },
                        fail() {
                            wx.hideLoading()
                        }
                    })
                    break
                case 'image':
                    wx.previewImage({
                        current: config.imageUrl + item.url,
                        urls: this.data.urls,
                        success(res) {},
                        fail() {}
                    })
                    break
            }
        },
    }
})